package router

import (
	_ "crow-k8s/docs"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"net/http"
)

func ServerRouter() {
	r := gin.Default()
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	//创建一个groupV1组，里边放一个检查存活的接口
	groupV1 := r.Group("/api/v1")
	{
		groupV1.GET("/ping", Ping)
		groupV1.GET("/version", Version)
		groupV1.GET("/liubei", LiuBei) //这是一个测试接口

		//登录
		groupV1.POST("/login", Login)           //登录服务
		groupV1.POST("/logout", Logout)         //用户登出
		groupV1.POST("/login/refresh", Refresh) //生成新token

		//admin接口
		groupV1.POST("/admin/user", admin(), CreateUser)                //创建用户
		groupV1.PUT("/admin/user_password", admin(), ResetUserPassword) //重置用户密码
		groupV1.GET("/admin/users", admin(), GetUsers)                  //获取用户信息，支持模糊查询
		groupV1.GET("/admin/users/:uuid", admin(), GetUser)             //删除指定用户
		groupV1.DELETE("/admin/users/:uuid", admin(), DeleteUser)       //删除指定用户
		groupV1.PUT("/admin/users", admin(), UpdateUsersInfo)           //修改用户信息

		//普通用户接口
		groupV1.PUT("/user/info", user(), UpdateUserInfo)         //用户修改自己的信息
		groupV1.PUT("/user/password", user(), UpdateUserPassword) //用户修改自己的密码
		groupV1.GET("/user/info", user(), GetUserInfo)            //用户查询自己信息

		groupV1.GET("/k8s/node/list", user(), GetNodeList) //查看所有node
		groupV1.GET("/k8s/node", user(), GetNode)          //查看制定node

		groupV1.GET("/k8s/namespace/list", user(), GetNamespaceList)              //查看namespace列表
		groupV1.GET("/k8s/namespace", user(), GetNamespace)                       //查看制定namespace
		groupV1.POST("/k8s/namespace", user(), CreateNamespace)                   //创建namespace
		groupV1.DELETE("/k8s/namespace/:namespace_name", user(), DeleteNamespace) //删除namespace

		groupV1.GET("/k8s/deployment/list", user(), GetDeploymentList)           //查询指定namespace的deployment列表
		groupV1.GET("/k8s/deployment", user(), GetDeployment)                    //查询指定deployment
		groupV1.POST("/k8s/deployment", user(), CreateDeployment)                //创建deployment
		groupV1.PUT("/k8s/deployment/volumes", user(), ApplyDeploymentByVolumes) //挂载configmap
		groupV1.PUT("/k8s/deployment", user(), ApplyDeployment)                  //修改deployment
		groupV1.PUT("/k8s/deployment/version", user(), RollBackDeployment)       //deployment回滚
		groupV1.DELETE("/k8s/deployment", user(), DeleteDeployment)              //删除deployment

		groupV1.GET("/k8s/service/list", user(), GetServiceList) //查询指定namespace下的service列表
		groupV1.GET("/k8s/service", user(), GetService)          //查询指定service
		groupV1.POST("/k8s/service", user(), CreateService)      //创建service
		groupV1.PUT("/k8s/service", user(), ApplyService)        //修改service信息
		groupV1.DELETE("/k8s/service", user(), DeleteService)    //删除指定service

		groupV1.POST("/k8s/configmap", user(), CreateConfigmap)      //创建configMap
		groupV1.GET("/k8s/configmap/list", user(), GetConfigmapList) //查询指定namespace下的configmap列表
		groupV1.GET("/k8s/configmap", user(), GetConfigmap)          //查询指定configmap
		groupV1.PUT("/k8s/configmap", user(), ApplyConfigmap)        //修改指定configmap
		groupV1.DELETE("/k8s/configmap", user(), DeleteConfigmap)    //删除指定configmap

		groupV1.GET("/k8s/pod/list", user(), GetPodList) //获取指定namespace下的pod列表
		groupV1.GET("/k8s/pod", user(), GetPod)          //获取指定pod
		groupV1.GET("/k8s/pod/logs", GetPodLogs)         //查看日志
		groupV1.DELETE("/k8s/pod", user(), DeletePod)    //删除指定pod

		groupV1.GET("/k8s/replicaset/list", user(), GetReplicasetList) //获取指定deployment的rs列表
		groupV1.GET("/k8s/replicaset", user(), GetReplicaset)          //获取指定rs信息

		groupV1.GET("/k8s/pvc/list", user(), GetPVCList) //获取指定namespace下的PVC
		groupV1.GET("/k8s/pvc", user(), GetPVC)          //查询指定pvc
		groupV1.POST("/k8s/pvc", user(), CreatePVC)      //创建pvc
		groupV1.DELETE("/k8s/pvc", user(), DeletePVC)    //删除指定pvc

		groupV1.POST("/k8s/secret", user(), CreateSecret)      //创建secret
		groupV1.GET("/k8s/secret/list", user(), GetSecretList) //获取指定namespace下的Secret列表
		groupV1.GET("/k8s/secret", user(), GetSecret)          //获取指定secret信息
		groupV1.PUT("/k8s/secret", user(), ApplySecret)        //更新secret
		groupV1.DELETE("/k8s/secret", user(), DeleteSecret)    //删除指定secret

	}

	//前端相关路由
	webGroup := r.Group("")
	{
		webGroup.GET("/", indexHtml)
		webGroup.StaticFS("/js", http.Dir("./web/js"))
		//r.StaticFile("/deamon.js", "./web/deamon.js")
	}

	r.Run(":1840")
}
